<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>2.分析生命周期</title>
    <script src="../js/vue.min.js"></script>
</head>

<body>
    <div id="root">
        <h2>当前的n值: {{n}}</h2>
        <button @click="add">点我n++</button>
        <button @click="bye">点我销毁VM</button>

    </div>
    <script type="text/javascript">

        const vm = new Vue({
            el: '#root',
            // template: `<div>
            //           <h2>当前的n值: {{n}}</h2>
            //           <button @click="add">点我n++</button>
            //           </div>`,
            data() {
                return {
                    n: 1,
                    opacity: 1
                }
            },

            methods: {
                add() {
                    console.log('add')
                    this.n++
                },
                bye() {
                    console.log('bye')
                    this.$destroy();
                }

            },
            beforeCreate() {
                console.log('beforeCreate');
            },
            created() {
                console.log('created');

            },
            beforeMount() {
                console.log('beforeMount');

            },
            //  Vue 完成模版的解析，并且初始的真实的DOM放入页面后(完成挂载)调用mounted
            mounted() {
                console.log('Vue 调用 mounted', this.$el instanceof HTMLElement)
            },
            beforeUpdate() {
                //  当前阶段，vm中的数据发生了变化，但是页面的DOM 还没有发生改变
                console.log('beforeUpdate');
            },
            updated() {
                console.log('updated');
            },
            beforeDestroy() {
                console.log('beforeDestroy');
            },
            destroyed() {
                console.log('destroyed');
            },
            watch: {
                n() {
                    console.log('n变了')
                }
            },

        });



    </script>

</body>

</html>